#include "stdafx.h"
#include ".\text.h"
#include "..\clientinterfaces.h"
std::wstring text::text_face = L"simhei";

text::text(uint s):
m_font_info(L"simhei",s)
{
	m_p_str=NULL;
	m_color=0xFFFFFFFF;
	
}

text::~text(void)
{
	if (m_p_str)
	{
		g_pLTTextureString->ReleaseTextureString(m_p_str);
		m_p_str=NULL;
	}
}

void text::set_font_hei( uint num )
{
	m_font_info.m_nHeight=num;
	if (m_p_str)
	{
		g_pLTTextureString->ReleaseTextureString(m_p_str);
		m_p_str=NULL;
	}
	m_p_str=g_pLTTextureString->CreateTextureString(m_string.c_str(), m_font_info) ;

}

void text::load_str( const wchar_t* str )
{
	m_string=str;
	if (m_p_str)
	{
		g_pLTTextureString->ReleaseTextureString(m_p_str);
		m_p_str=NULL;
	}
	m_p_str=g_pLTTextureString->CreateTextureString(str, m_font_info) ;

}

void text::render()
{
	g_pLTTextureString->RenderString (m_p_str,  
	g_pLTCDrawPrim,	LTVector2f(m_x,m_y),m_color);

}

const wchar_t* text::get_cstr()
{
	return m_string.c_str();
}

HTEXTURE text::get_htex()
{
	g_pLTTextureString->GetTextureImage(m_p_str,m_htex);
	return m_htex;

}

uint32 text::get_length()
{
	uint32 temp;
	g_pLTTextureString->GetStringLength(m_p_str,&temp);
	return temp;

}

void text::set_color( uint32 color/*=0xFFFFFFFF*/ )
{
	m_color=color;

}

void text::set_colors( uint32 a,uint32 r,uint32 g,uint32 b )
{
	m_color=b+g*256+r*256*256+a*256*256*256;

}